<!-- 发货资料填写 -->
<template>
	<view class="aftersale-dispatch-bill">
		<uniForms class="form">
			<formListItem
				class="item"
				placeholder="请选择快递公司"
				:type="'selector'"
				:picker-list="courierCompanyPickerList"
				:arrow-show="true"
				:value.sync="form.fastMail"
			></formListItem>
			<formListItem class="item" placeholder="请填写快递单号" :value.sync="form.billwayNo"></formListItem>
		</uniForms>
		<button class="btn btn-yellow save-btn" @click="submit">提交</button>
	</view>
</template>

<script>
import uniForms from '@/components/uni-forms/uni-forms.vue';
import formListItem from '@/components/form-list-item/form-list-item.vue';
export default {
	components: {
		uniForms,
		formListItem
	},
	data() {
		return {
			refundId: '',
			orderNo: null,
			refundNo: null,
			serveType: null,
			form: {
				//地址数据

				fastMail: '', //快递公司
				billwayNo: '' //快递单号
			},
			courierCompanyPickerList: [
				// 快递服务公司列表
				{
					label: '顺丰速运',
					value: '顺丰速运'
				},
				{
					label: '中通快递',
					value: '中通快递'
				},
				{
					label: '申通快递',
					value: '申通快递'
				},
				{
					label: '圆通快递',
					value: '圆通快递'
				},
				{
					label: '韵达快递',
					value: '韵达快递'
				},
				{
					label: '国通快递',
					value: '国通快递'
				},
				{
					label: '中国邮政',
					value: '中国邮政'
				}
			]
		};
	},
	methods: {
		submit() {
			if(this.verification())
			this.$store
				.dispatch('editRefundState', {
					orderNo: this.orderNo,
					refundNo: this.refundNo,
					serveType: this.serveType,
					fastMail: this.form.fastMail, //快递公司
					billwayNo: this.form.billwayNo, //快递单号
					status: 2
				})
				.then(res => {
					
					
					setTimeout(()=>{
						uni.showToast({
							icon: 'success',
							mask: true,
							title: '提交成功',
							duration: 2000
						});
					},500)

					setTimeout(() => {
						uni.redirectTo({
							url: `/pages/aftersale/aftersale-detail?id=${this.refundId}&refundNo=${this.refundNo}`
						});
					}, 2000);
				});
		},
		verification() {
			// 验证
			if (!this.form.fastMail || this.form.fastMail == '') {
				uni.showToast({
					icon: 'none',
					mask: true,
					duration: 2000,
					title: '请选择快递公司！'
				});
				return false;
			} else if (!this.form.billwayNo || this.form.billwayNo == '') {
				uni.showToast({
					icon: 'none',
					mask: true,
					duration: 2000,
					title: '请填写快递单号！'
				});
				return false;
			} else {
				return true;
			}
		},
	
	},
	
	onLoad(option) {
		if (option.id) this.refundId = option.id;
		if (option.orderNo) this.orderNo = option.orderNo;
		if (option.refundNo) this.refundNo = option.refundNo;
		if (option.serveType) this.serveType = parseInt(option.serveType);
	}
};
</script>

<style lang="scss" scoped>
.aftersale-dispatch-bill {
	width: 100%;

	.form {
		width: 100%;
		box-sizing: border-box;

		.item {
			display: flex;
			width: 100%;
			padding: 5rpx 20rpx;
			background-color: #fff;
			box-sizing: border-box;
		}
		.item:nth-child(1) {
			border-radius: 8px 8px 0px 0px;
		}
		.item:nth-last-child(1) {
			border-radius: 0px 0px 8px 8px;
		}
		.item:nth-last-child(n + 2) {
			border-bottom: 2rpx solid #efeff0;
		}
	}
	.save-btn {
		display: block;
		width: 90%;
		font-size: 30rpx;
		padding: 14rpx 0rpx;
		margin: auto;
		margin-top: 150rpx;
	}
}
</style>
